#!/usr/bin/python2.4
#
# Copyright 2011 Google Inc. All Rights Reserved.

from gaesessions import get_current_session
from git.util import git_context

class LoginUtil:
    
    @staticmethod
    def SetUserLogin(email):
        session = get_current_session()
        session['email'] = email
        return session
    
    @staticmethod
    def Logout():
        session = get_current_session()
        if session.is_active():
            session.terminate()
    
    @staticmethod
    def IsUserLogin():
        session_manager = git_context.GitContext.GetSessionManager()
        user_account = session_manager.GetSessionAccount()
        if user_account:
            return True
        else:
            return False
    
    @staticmethod
    def GetLoginedUserEmail():
        session_manager = git_context.GitContext.GetSessionManager()
        user_account = session_manager.GetSessionAccount()
        if user_account:
            return user_account.GetEmail()
        else:
            return None
    
    @staticmethod
    def GetLoginedGitAccount():
        session_manager = git_context.GitContext.GetSessionManager()
        user_account = session_manager.GetSessionAccount()
        return user_account